package com.example.neusoft.a16110100126yttordering.fragments;


import android.content.Context;
import android.os.Bundle;
import android.service.carrier.CarrierService;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Switch;
import android.widget.Toast;

import com.example.neusoft.a16110100126yttordering.Adapter.ShopAdapter;
import com.example.neusoft.a16110100126yttordering.R;
import com.example.neusoft.a16110100126yttordering.activities.MainActivity;
import com.example.neusoft.a16110100126yttordering.bean.CollectStatus;
import com.example.neusoft.a16110100126yttordering.bean.Result;
import com.example.neusoft.a16110100126yttordering.bean.Shop;
import com.example.neusoft.a16110100126yttordering.common.Constants;
import com.example.neusoft.a16110100126yttordering.listener.RetrofitListener;
import com.example.neusoft.a16110100126yttordering.model.CollectionModel;
import com.example.neusoft.a16110100126yttordering.model.FoodModel;
import com.example.neusoft.a16110100126yttordering.model.ShopModel;

import java.util.List;

public class ShopFragment extends BaseFragment implements RetrofitListener{
    private RecyclerView recyclerView;
    private ShopAdapter adapter;
    private Context context;
    private Result result;
    private int Shop_id=1;
    private List<CollectStatus>data;
    private boolean isFirstLoading = true;
    @Override
    public void onResume() {
        super.onResume();
        if (!isFirstLoading) {
//            initData();
        }
        isFirstLoading = false;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        setLayout_file(R.layout.fragment_shop);
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    void initViews(){
        recyclerView=(RecyclerView)view.findViewById(R.id.recyclerView1);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    }

    @Override
    void initEvents() {

    }

    void initData(){
        iscollected();
        getallshops();

    }

    private void getallshops(){
        ShopModel shopModel=new ShopModel();
        shopModel.getAllShops(this);
    }

    private void iscollected(){
        CollectionModel collectionModel=new CollectionModel();
        collectionModel.getAllUserCollection(getUser_id(),0,this);
    }
    @Override
    public void onSuccess(Object o, int flag) {
        switch(flag){
            case Constants.COLLECTION:
                System.out.println("-----lalala---stt---wozhendehenaini");
                data=(List<CollectStatus>)o;
                break;
            case Constants.GETALLSHOPS:
                adapter=new ShopAdapter(getActivity(),(List<Shop>)o,data,R.layout.item);
                recyclerView.setAdapter(adapter);
                break;
        }
    }

    @Override
    public void onFail() {
//        showToast("网络连接失败");
        Toast.makeText(context, "网络连接失败",Toast.LENGTH_SHORT).show();
    }
}
